package com.ssd.controller.inner;


import com.ssd.api.couponAndIntegral.CouponApi;
import com.ssd.api.couponAndIntegral.dto.CouponUseBackReqDTO;
import com.ssd.api.couponAndIntegral.dto.CouponUseReqDTO;
import com.ssd.api.couponAndIntegral.dto.AvailableCouponsResDTO;
import com.ssd.api.couponAndIntegral.dto.CouponUseResDTO;
import com.ssd.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 内部接口-我的优惠券表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-21
 */
@RestController("innerCouponController")
@RequestMapping("/inner/coupon")
@Api(tags = "内部接口-我的优惠券表控制器")
@Validated
public class CouponController implements CouponApi {
    @Resource
    private ICouponService couponService;

    /**
     *根据金额计算用户可用优惠券列表
     * @param totalAmount 金额
     * @return
     */
    @GetMapping("/getAvailable")
    @ApiOperation(value = "获取可用优惠券列表")
    public List<AvailableCouponsResDTO> gatAvailable(@RequestParam("totalAmount") BigDecimal totalAmount){
            return couponService.getAvailable(totalAmount);
    }

    /**
     * 使用优惠券，并返回优惠金额
     * @param couponUseReqDTO 使用优惠券参数
     * @return
     */
    @PostMapping("/use")
    @ApiOperation(value = "优惠券使用")
    public CouponUseResDTO use(@RequestBody CouponUseReqDTO couponUseReqDTO){
        return couponService.use(couponUseReqDTO);
    }

    /**
     * 优惠券回退接口
     * @param couponUseBackReqDTO 回退参数
     */
    @PostMapping("/useBack")
    @ApiOperation(value = "优惠券回退接口")
    public void useBack(@RequestBody CouponUseBackReqDTO couponUseBackReqDTO){
        couponService.useBack(couponUseBackReqDTO);
    }
}
